package com.hll.javaee.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: JavaWebDemo-01
 * @description:
 * @author: Mr.Hu
 * @create: 2021-03-04 12:38
 */
public class ServletRe extends HttpServlet {
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    doGet(request, response);
  }

  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // 重定向，可以改变地址栏url,302
    response.setHeader("Location", "img");
    response.setStatus(HttpServletResponse.SC_FOUND);
    response.sendRedirect("img");

    // 请求转发,地址栏不变，但实际上转发给hello servlet 处理， 状态码307
    // this.getServletContext().getNamedDispatcher("/hello").forward(request, response);
  }
}
